targetPath=myOneceLove/target

myBuild(){
    echo 更新仓库 $1;
    if [ ! -d "$1" ];then
        echo ==========没有项目$1需要clone下来
        git clone https://lianlianyi:since9527.@gitee.com/lianlianyi/$1.git
        cd ./$1
		pwd
    else
        echo ==========更新git项目:$1
        pwd
        cd ./$1
        pwd
        mypull=$(git pull)
		echo "git 更新:" $mypull
		if [[ "1" == "$2" ]];then
			echo "强制编译:" $1
            echo ==========编译项目 $1
            mvn clean install -Dmaven.test.skip=true -Ponline
            rc=$?
            if [[ $rc -ne 0 ]] ; then
              echo ==========编译异常!!!!!$1
              cd -
              pwd
              exit $rc
            fi
		else
			if [[ "Already up-to-date." != "$mypull" ]];then
	        	echo "有更新需要编译项目"
	            echo ==========编译项目 $1
	            mvn clean install -Dmaven.test.skip=true -Ponline
	            rc=$?
	            if [[ $rc -ne 0 ]] ; then
	              echo ==========编译异常!!!!!$1
	              cd -
	              pwd
	              exit $rc
	            fi
	        fi
		fi
 		
    fi
    echo ==========返回上一层目录
    cd ..
	pwd
}

#记录开始时间
starttime=`date +'%Y-%m-%d %H:%M:%S'`

myBuild kyubi 0
myBuild myOneceLove 1

cd $targetPath
pwd
nohup java -jar `find ./ -name "myOneceLove-*.jar"`  &
echo "启动程序完成!!!!"
endtime=`date +'%Y-%m-%d %H:%M:%S'`
start_seconds=$(date --date="$starttime" +%s);
end_seconds=$(date --date="$endtime" +%s);


#统计时间差
endtime=`date +'%Y-%m-%d %H:%M:%S'`
start_seconds=$(date --date="$starttime" +%s);
end_seconds=$(date --date="$endtime" +%s);
echo "本次运行时间： "$((end_seconds-start_seconds))"s"
